package com.sun.myexception;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 集中处理异常类，需加入ioc容器中
 * @author sun
 */
@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = {ArithmeticException.class})
    public String MyhandleException01(Exception e , Model model){
        System.out.println("handleException01:"+e.getMessage());
        model.addAttribute("errorMsg","ControllerAdvice01"+e);
        return "error";
    }

    /*@ExceptionHandler(value = {NullPointerException.class})
    public String handleException02(Exception e ,Model model){
        System.out.println("handleException01:"+e.getMessage());
        model.addAttribute("errorMsg","ControllerAdvice02"+e);
        return "error";
    }*/
}
